package com.Register.listener;

import com.Register.dto.EnrollActivityTempDTO;
import com.Register.es.ActivityDoc;
import com.Register.service.VolunteerActivityService;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/*
异步载入新添加的活动文档
 */
@Component
@RequiredArgsConstructor
public class LoadActivityDocListener {
    @Resource
    private VolunteerActivityService volunteerActivityService;

    //设置队列名
    public static final String LOAD_ACTIVITY_DOC_QUEUE_NAME = "loadActivity.loadActivity.queue";
    //设置交换机
    public static final String LOAD_ACTIVITY_DOC_EXCHANGE_NAME = "loadActivity.direct";
    //设置key
    public static final String LOAD_ACTIVITY_DOC_ROUTING_KEY = "loadActivity.success";

    @RabbitListener(bindings = {@QueueBinding(
            value = @Queue(name = LOAD_ACTIVITY_DOC_QUEUE_NAME,durable = "true"),
            exchange = @Exchange(name = LOAD_ACTIVITY_DOC_EXCHANGE_NAME),
            key = LOAD_ACTIVITY_DOC_ROUTING_KEY
    )},
            // 在@RabbitListener注解中指定容器工厂
            containerFactory = "customContainerFactory")
    public void LoadActivity(ActivityDoc activityDoc) throws IOException {
        volunteerActivityService.addDocument(activityDoc);
    }
}
